import QtQuick 2.0
import QtQuick.Controls 2.3
import "storage.js" as Storage

Item {
    id:root
    width: 850
    height: 580
    property real minSize:  Math.min(width/850, height/580)
    property real textSize:  40*minSize
    property color majorColor: "#44fdfd"

    onFocusChanged:{
        if(!focus) return
        refurbishA()
        refurbishB()
    }

    function readRegSingalLim(handle, sqlName){
        handle.valueText = Storage.readRegSingalLimit(sqlName)
    }
    function writeRegSingalLim(handle, sqlName){
        Storage.writeRegSingalLimit(handle.valueText, sqlName)
    }
    function readRegScope(handle, sqlName){
        handle.tipText = Storage.readRegScope(sqlName)
    }

    function refurbishA()
    {
        readRegSingalLim(sp0_a, "A套欠励限制 SP0")
        readRegSingalLim(sp25_a, "A套欠励限制 SP25")
        readRegSingalLim(sp50_a, "A套欠励限制 SP50")
        readRegSingalLim(sp75_a, "A套欠励限制 SP75")
        readRegSingalLim(sp100_a, "A套欠励限制 SP100")
    }
    function refurbishB()
    {
        readRegSingalLim(sp0_b, "B套欠励限制 SP0")
        readRegSingalLim(sp25_b, "B套欠励限制 SP25")
        readRegSingalLim(sp50_b, "B套欠励限制 SP50")
        readRegSingalLim(sp75_b, "B套欠励限制 SP75")
        readRegSingalLim(sp100_b, "B套欠励限制 SP100")
    }
    Timer{
        interval: 2000
        repeat: false
        triggeredOnStart: false
        running: true
        onTriggered: {
            readRegScope(sp0_a, "A套欠励限制 SP0")
            readRegScope(sp25_a, "A套欠励限制 SP25")
            readRegScope(sp50_a, "A套欠励限制 SP50")
            readRegScope(sp75_a, "A套欠励限制 SP75")
            readRegScope(sp100_a, "A套欠励限制 SP100")
            readRegScope(sp0_b, "B套欠励限制 SP0")
            readRegScope(sp25_b, "B套欠励限制 SP25")
            readRegScope(sp50_b, "B套欠励限制 SP50")
            readRegScope(sp75_b, "B套欠励限制 SP75")
            readRegScope(sp100_b, "B套欠励限制 SP100")
        }
    }

    SwipeView
    {
        id: sv_this
        width:parent.width
        height: parent.height*0.85
        clip: true
        Component.onCompleted:{contentItem.highlightMoveDuration = 0}       //将移动时间设为0

        onCurrentIndexChanged: {
            if(sv_this.currentIndex===0) {button.checked=true;button2.checked=false}
            if(sv_this.currentIndex===1) {button2.checked=true;button.checked=false}
        }

        Item{
            Text {
                y: 30*root.minSize
                color: majorColor
                text: qsTr("A通道欠励参数")
                anchors.horizontalCenter: parent.horizontalCenter
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 40*root.minSize
            }

            Image {
                y: 90*root.minSize
                width: sourceSize.width*0.75*root.minSize
                height: sourceSize.height*0.75*root.minSize
                anchors.horizontalCenter: parent.horizontalCenter
                source: "../picture/UE_New.png"
                fillMode: Image.PreserveAspectFit
                property real textSize: 18*root.minSize

                EXC_Normal_DoubleTextSytle2 {
                    id: sp0_a
                    x: 90*root.minSize
                    y: 360*root.minSize
                    textSize: parent.textSize
                    funcText: "SP0:"
                }
                EXC_Normal_DoubleTextSytle2 {
                    id: sp25_a
                    x: 150*root.minSize
                    y: 290*root.minSize
                    textSize: parent.textSize
                    funcText: "SP25:"
                }

                EXC_Normal_DoubleTextSytle2 {
                    id: sp50_a
                    x: 220*root.minSize
                    y: 220*root.minSize
                    textSize: parent.textSize
                    funcText: "SP50:"
                }

                EXC_Normal_DoubleTextSytle2 {
                    id: sp75_a
                    x: 290*root.minSize
                    y: 140*root.minSize
                    textSize: parent.textSize
                    funcText: "SP75:"
                }

                EXC_Normal_DoubleTextSytle2 {
                    id: sp100_a
                    x: 370*root.minSize
                    y: 75*root.minSize
                    textSize: parent.textSize
                    funcText: "SP100:"
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: btn_ASave
                nameFontpixelSize: 25*root.minSize
                anchors.right: parent.right
                anchors.rightMargin: 50*minSize
                y: 410*root.minSize
                width: 140*root.minSize
                height: 50*root.minSize
                nameText: qsTr("保存参数")

                onClicked: {
                    writeRegSingalLim(sp0_a, "A套欠励限制 SP0")
                    writeRegSingalLim(sp25_a, "A套欠励限制 SP25")
                    writeRegSingalLim(sp50_a, "A套欠励限制 SP50")
                    writeRegSingalLim(sp75_a, "A套欠励限制 SP75")
                    writeRegSingalLim(sp100_a, "A套欠励限制 SP100")
                    timerA_ass.start()
                }

                Timer{
                    id:timerA_ass
                    interval: 700
                    repeat: true
                    triggeredOnStart: false
                    property int thisCounter: 0
                    onTriggered: {
                        refurbishA()
                        thisCounter++
                        if(thisCounter>3) {
                            thisCounter=0
                            stop()
                        }
                    }
                }
            }
            onFocusChanged:{
                if(!focus) return
                refurbishA()
            }
        }


        Item{
            Text {
                y: 30*root.minSize
                color: majorColor
                text: qsTr("B通道欠励参数")
                anchors.horizontalCenter: parent.horizontalCenter
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 40*root.minSize
            }

            Image {
                y: 90*root.minSize
                width: sourceSize.width*0.75*root.minSize
                height: sourceSize.height*0.75*root.minSize
                anchors.horizontalCenter: parent.horizontalCenter
                source: "../picture/UE_New.png"
                fillMode: Image.PreserveAspectFit
                property real textSize: 18*root.minSize

                EXC_Normal_DoubleTextSytle2 {
                    id: sp0_b
                    x: 90*root.minSize
                    y: 360*root.minSize
                    textSize: parent.textSize
                    funcText: "SP0:"
                }
                EXC_Normal_DoubleTextSytle2 {
                    id: sp25_b
                    x: 150*root.minSize
                    y: 290*root.minSize
                    textSize: parent.textSize
                    funcText: "SP25:"
                }

                EXC_Normal_DoubleTextSytle2 {
                    id: sp50_b
                    x: 220*root.minSize
                    y: 220*root.minSize
                    textSize: parent.textSize
                    funcText: "SP50:"
                }

                EXC_Normal_DoubleTextSytle2 {
                    id: sp75_b
                    x: 290*root.minSize
                    y: 140*root.minSize
                    textSize: parent.textSize
                    funcText: "SP75:"
                }

                EXC_Normal_DoubleTextSytle2 {
                    id: sp100_b
                    x: 370*root.minSize
                    y: 75*root.minSize
                    textSize: parent.textSize
                    funcText: "SP100:"
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: btn_BSave
                nameFontpixelSize: 25*root.minSize
                anchors.right: parent.right
                anchors.rightMargin: 50*minSize
                y: 410*root.minSize
                width: 140*root.minSize
                height: 50*root.minSize
                nameText: qsTr("保存参数")
                onClicked: {
                    writeRegSingalLim(sp0_b, "B套欠励限制 SP0")
                    writeRegSingalLim(sp25_b, "B套欠励限制 SP25")
                    writeRegSingalLim(sp50_b, "B套欠励限制 SP50")
                    writeRegSingalLim(sp75_b, "B套欠励限制 SP75")
                    writeRegSingalLim(sp100_b, "B套欠励限制 SP100")
                    timerB_ass.start()
                }

                Timer{
                    id:timerB_ass
                    interval: 700
                    repeat: true
                    triggeredOnStart: false
                    property int thisCounter: 0
                    onTriggered: {
                        refurbishB()
                        thisCounter++
                        if(thisCounter>3) {
                            thisCounter=0
                            stop()
                        }
                    }
                }
            }
            onFocusChanged:{
                if(!focus) return
                refurbishB()
            }
        }
    }

    EXC_Normal_BtnSytle {
        id: button
        nameText: qsTr("A通道")
        width: parent.width*0.15
        height: parent.height*0.09
        checked: true
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.1
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            if(sv_this.currentIndex===0) checked = true;
            else sv_this.currentIndex = 0
        }
    }

    EXC_Normal_BtnSytle {
        id: button2
        nameText: qsTr("B通道")
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.43
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            if(sv_this.currentIndex===1) checked = true;
            else sv_this.currentIndex = 1
        }
    }

    EXC_Normal_BtnUncheckStyle {
        id: button3
        nameText: qsTr("返回")
        nameFontpixelSize: 30*Math.min(root.width/850, root.height/580)
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.75
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            sw.currentIndex = 0
        }
    }
}
